package com.ruoyi.common.pay;

import org.springframework.beans.factory.annotation.Value;

import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

public class MyConfig extends WXPayConfig {

    private byte[] certData;
    @Value("${com.wx.key-path}")
    private String apiclientCert;
    @Value("${com.wx.app.app-id}")
    private String wxAppAppid;
    @Value("${com.wx.mch-id}")
    private String mchId;
    @Value("${com.wx.app.app-secret}")
    private String secret;

    public MyConfig() throws Exception {
        File file = new File(apiclientCert);
        InputStream certStream = new FileInputStream(file);
        this.certData = new byte[(int) file.length()];
        certStream.read(this.certData);
        certStream.close();
    }
/*
 * APP
 */
    public String getAppID() {
        return wxAppAppid;
    }

    public String getMchID() {
        return mchId;
    }

    public String getKey() {
        return secret;
    }


    /*
     * 麦咖小程序
     */
    public String getAppID1() {
        return "wx12b7186a2b3a5779";
    }
    /*
     * 活动小程序
     */
    public String getActionAppID() {
    	return "wx93e374801e532269";
    }
    /*
     * 麦咖小程序
     */
//    public String getMchID1() {
//        return "1529572931";
//    }

    public String getKey1() {
        return "0cfa83488ec8204c1bae40cb4cd8001b";
    }


    public static String getWxpayNotify(HttpServletRequest request) {
//    	  StringBuffer requestURL = request.getRequestURL();
//      return requestURL.substring(0,requestURL.indexOf("/orderPay"))+"/wxpayNotify";


    	  String requestURL = "https://api.mkcar.com.cn/mycarAPP/appPay";
          return requestURL+"/wxpayNotify";
    }
    public static String getActionWxpayNotify(HttpServletRequest request) {
//    	StringBuffer requestURL = request.getRequestURL();
//    	return requestURL.substring(0,requestURL.indexOf("/actionOrderPay"))+"/actionWxpayNotify";


    	  String requestURL = "https://api.mkcar.com.cn/mycarAPP/appPay";
          return requestURL+"/actionWxpayNotify";
    }
    /**
     * 获取微信退款回调地址
     * @author gongchengbing
     * @date 2019年7月30日
     * @verion 1.0
     * @param request
     * @return
     */
    public static String getWxrefundNotify(HttpServletRequest request) {
//    	StringBuffer requestURL = request.getRequestURL();
//    	return requestURL.substring(0,requestURL.indexOf("/orderPay"))+"/wxrefundNotify";


    	  String requestURL = "https://api.mkcar.com.cn/mycarAPP/appPay";
          return requestURL+"/wxrefundNotify";
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

	@Override
    IWXPayDomain getWXPayDomain() {
		IWXPayDomain pd	=  new WXPayDomain();
		// TODO Auto-generated method stub
		return pd ;
	}
}
